package com.slz3.business.frame.util;

public class HumpToUnderline {

    public static String convert(String name) {
        char[] cs = name.toCharArray();
        short humpCount = 0;// 驼峰数量
        for (char c : cs) {
            if (c >= 'A' && c <= 'Z') {
                humpCount++;
            }
        }
        // 驼峰数量+name字符数为新字符串的数量
        char[] newcs = new char[cs.length + humpCount];
        humpCount = 0;
        for (short i = 0; i < name.length(); i++) {
            if (cs[i] >= 'A' && cs[i] <= 'Z') {
                cs[i] += 32;/**A-->a**/
                newcs[i+humpCount] = '_';
                humpCount++;
            }
            newcs[i+humpCount] = cs[i];
        }
        return String.valueOf(newcs);
    }

}
